package cn.huhst.cas.weisiqian.pojo;

import cn.huhst.cas.weisiqian.util.JSON;

public class Comment {

	private int commentid; /* 评论ID */
	private int parentid; /* 评论的父亲ID：评论帖子时是帖子ID，评论新闻时是新闻ID，评论评论时是评论ID */
	private int commenttype; /* 评论类型:0表示评论帖子，1表示评论新闻，2表示评论其他人的评论 */
	private String content; /* 评论内容 */
	private String author; /* 发布评论的人 */
	private java.sql.Date writetime; /* 评论时间 */
	private int likecount; /* 点赞数 */
	private int dislikecount; /* 讨厌数目 */

	/**
	 * 评论ID为正整数
	 */
	public static final String commentidRegx = "^\\d+$";
	/**
	 * 评论的父亲ID为正整数
	 */
	public static final String parentidRegx = "^\\d+$";
	/**
	 * 评论类型为正整数
	 */
	public static final String commenttypeRegx = "^\\d+$";
	/**
	 * 评论内容由汉字，大小写字母，数字，“-”，“.”,“ ”组成,长度不超过127
	 */
	public static final String contentRegx = "^([\\u4e00-\\u9fa5]|[0-9a-zA-Z]|-|.| ){1,127}$";
	/**
	 * 评论者由2到5个汉字组成或者由4到10个词字符组成（词字符：大小写字母和数字）
	 */
	public static final String authorRegx = "^([\\u4e00-\\u9fa5]{2,5})|([a-zA-Z0-9]{4,10})$";
	/**
	 * 点赞数为正整数
	 */
	public static final String likecountRegx = "^\\d+$";
	/**
	 * 讨厌数为正整数
	 */
	public static final String dislikecountRegx = "^\\d+$";

	public static final JSON checkCommentid(String commentid, JSON json) {
		if (commentid == null || !commentid.matches(commentidRegx)) {
			json.put("commentid", "评论ID为正整数");
		}
		return json;
	}

	public static final JSON checkParentid(String parentid, JSON json) {
		if (parentid == null || !parentid.matches(parentidRegx)) {
			json.put("parentid", "评论的父亲ID为正整数");
		}
		return json;
	}

	public static final JSON checkCommenttype(String commenttype, JSON json) {
		if (commenttype == null || !commenttype.matches(commenttypeRegx)) {
			json.put("commenttype", "评论类型为正整数");
		}
		return json;
	}

	public static final JSON checkContent(String content, JSON json) {
		if (content == null || !content.matches(contentRegx)) {
			json.put("content", "评论内容由汉字，大小写字母，数字，“-”，“.”,“ ”组成,长度不超过127");
		}
		return json;
	}

	public static final JSON checkAuthor(String author, JSON json) {
		if (author == null || !author.matches(authorRegx)) {
			json.put("author", "评论者由2到5个汉字组成或者由4到10个词字符组成（词字符：大小写字母和数字）");
		}
		return json;
	}

	public static final JSON checkLikecount(String likecount, JSON json) {
		if (likecount == null || !likecount.matches(likecountRegx)) {
			json.put("likecount", "点赞数为正整数");
		}
		return json;
	}

	public static final JSON checkDislikecount(String dislikecount, JSON json) {
		if (dislikecount == null || !dislikecount.matches(dislikecountRegx)) {
			json.put("dislikecount", "讨厌数为正整数");
		}
		return json;
	}

	public JSON checkformat() {
		JSON json = new JSON();
		json = checkAuthor(author, json);
		json = checkContent(content, json);
		return json;
	}

	public int getCommentid() {
		return commentid;
	}

	public void setCommentid(int commentid) {
		this.commentid = commentid;
	}

	public int getParentid() {
		return parentid;
	}

	public void setParentid(int parentid) {
		this.parentid = parentid;
	}

	public int getCommenttype() {
		return commenttype;
	}

	public void setCommenttype(int commenttype) {
		this.commenttype = commenttype;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public java.sql.Date getWritetime() {
		return writetime;
	}

	public void setWritetime(java.sql.Date writetime) {
		this.writetime = writetime;
	}

	public int getLikecount() {
		return likecount;
	}

	public void setLikecount(int likecount) {
		this.likecount = likecount;
	}

	public int getDislikecount() {
		return dislikecount;
	}

	public void setDislikecount(int dislikecount) {
		this.dislikecount = dislikecount;
	}

	@Override
	public String toString() {
		return "Comment [commentid=" + commentid + ", parentid=" + parentid + ", commenttype=" + commenttype
				+ ", content=" + content + ", author=" + author + ", writetime=" + writetime + ", likecount="
				+ likecount + ", dislikecount=" + dislikecount + "]";
	}

}
